package com.zhu.service;

import com.zhu.mapper.*;
import com.zhu.pojo.Debt;

import com.zhu.pojo.Expend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class DebtService {
    @Autowired
    DebtMapper debtMapper;
    @Autowired
    UserMapper userMapper;


    public List<Debt> getAll(String  username) {
        int userId= userMapper.getUserByName(username).getId(); //获取用户id
        return debtMapper.getAll(userId);
    }

    public List<Debt> getAllByAdmin() {
        return debtMapper.getAllByAdmin();
    }


    public List<Debt> getByCondition(Debt debt) {
        return  debtMapper.getByCondition(debt);
    }

    public boolean save(Debt debt) {
        int row = debtMapper.add(debt);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }


    public boolean upd(Debt debt) {
        int row = debtMapper.update(debt);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean del(int  id) {
        int row = debtMapper.delete(id);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public List<Debt> getByAdmin(Debt debt) {
        return debtMapper.getByAdmin(debt);
    }
}

